﻿/*------------------------------------------------------------------------------
* 版权说明：本文件为成都纵横科技有限责任公司版权所有，
* 未经过成都纵横科技有限责任公司书面授权任何人或公司不得使用此文件中的部分和全部内容
* 单元名称：NET_AJ_JK_RESULT
* 单元描述：NET_AJ_JK_RESULT 查看、添加、修改详细页面。
* 创建人： 郭丰
* 创建日期：12/18/2017
* 修改日志：   
----------------------------------------------------------------------------*/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using gfLibrary;
using DBUtility;

using Model;
using BLL;
using System.Text;

namespace IYAKASAPortal.LabourVerify
{
    public partial class NET_AJ_JK_RESULT_Insert_Update : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.IsPostBack == false)
            {
                txtLogTime.Text = DateTime.Now.ToString("yyyy-MM-dd");

                string strMode = Request["m"];

                if((strMode == "u")||(strMode == "b")||(strMode == "r"))
                {
                    string strId = Request["UniqueKey"];

                    NET_AJ_JK_RESULT_BLL m_NET_AJ_JK_RESULT_BLL = new NET_AJ_JK_RESULT_BLL();

                    if(m_NET_AJ_JK_RESULT_BLL.Exists(Convert.ToInt32(strId)) == true)
                    {
                        NET_AJ_JK_RESULT m_NET_AJ_JK_RESULT = new NET_AJ_JK_RESULT();
                        m_NET_AJ_JK_RESULT = m_NET_AJ_JK_RESULT_BLL.GetModel(Convert.ToInt32(strId));
                        txtJYXM.Text = m_NET_AJ_JK_RESULT.ID.ToString();
                        txtID.Text = m_NET_AJ_JK_RESULT.ID.ToString();
                        txtLWLSH.Text = m_NET_AJ_JK_RESULT.LWLSH;
                        txtLWType.Text = m_NET_AJ_JK_RESULT.LWType;
                        txtJKName.Text = m_NET_AJ_JK_RESULT.JKName;

                        txtSendInfo.Text = HttpUtility.UrlDecode(m_NET_AJ_JK_RESULT.SendInfo);
                        txtRevcInfo.Text = HttpUtility.UrlDecode(m_NET_AJ_JK_RESULT.RevcInfo, Encoding.UTF8);
                        txtIsSuc.Text = m_NET_AJ_JK_RESULT.IsSuc;
                        txtLogTime.Text = ((DateTime)m_NET_AJ_JK_RESULT.LogTime).ToString("yyyy-MM-dd HH:mm:ss");
                    }
                    else
                    {
                        gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "请选择一条记录！");
                        gfAjaxJs.SetGoToUrl(this.UpdatePanel1, "NET_AJ_JK_RESULT_List.aspx");
                    }

                    if((strMode == "b")||(strMode == "r"))
                    {
                        txtID.ReadOnly = true;
                        txtID.CssClass = "csstextboxreadonly";
                        txtLWLSH.ReadOnly = true;
                        txtLWLSH.CssClass = "csstextboxreadonly";
                        txtLWType.ReadOnly = true;
                        txtLWType.CssClass = "csstextboxreadonly";
                        txtJKName.ReadOnly = true;
                        txtJKName.CssClass = "csstextboxreadonly";
                        txtJYXM.ReadOnly = true;
                        txtJYXM.CssClass = "csstextboxreadonly";
                        txtSendInfo.ReadOnly = true;
                        txtSendInfo.CssClass = "csstextboxreadonly";
                        txtRevcInfo.ReadOnly = true;
                        txtRevcInfo.CssClass = "csstextboxreadonly";
                        txtIsSuc.ReadOnly = true;
                        txtIsSuc.CssClass = "csstextboxreadonly";
                        txtLogTime.ReadOnly = true;
                        txtLogTime.CssClass = "csstextboxreadonly";
                        btnLogTimeCalendar.Visible = false;
                        btnSave.Visible = false;
                    }

                    if(strMode == "r")
                    {
                        btnBack.Visible = false;
                    }
                }
              
            }

            btnLogTimeCalendar.Attributes["onclick"] = "meizz_calendar(document.all.txtLogTime);return false;";
            btnBack.Attributes["onclick"] = "javascript:window.location.href='NET_AJ_JK_RESULT_List.aspx';return false;";
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            string strID = txtID.Text.Trim();
            string strLWLSH = txtLWLSH.Text.Trim();
            string strLWType = txtLWType.Text.Trim();
            string strJKName = txtJKName.Text.Trim();
            string strJYXM = txtJYXM.Text.Trim();
            string strSendInfo = txtSendInfo.Text.Trim();
            string strRevcInfo = txtRevcInfo.Text.Trim();
            string strIsSuc = txtIsSuc.Text.Trim();
            string strLogTime = txtLogTime.Text.Trim();

            if (gfValidate.Is_DateTime(strLogTime) == false)
            {
                gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "[LogTime]不是有效的日期格式。");
                return;
            }

            NET_AJ_JK_RESULT m_NET_AJ_JK_RESULT = new NET_AJ_JK_RESULT();
            NET_AJ_JK_RESULT_BLL m_NET_AJ_JK_RESULT_BLL = new NET_AJ_JK_RESULT_BLL();

            m_NET_AJ_JK_RESULT.LWLSH = strLWLSH;
            m_NET_AJ_JK_RESULT.LWType = strLWType;
            m_NET_AJ_JK_RESULT.JKName = strJKName;
            m_NET_AJ_JK_RESULT.SendInfo = strSendInfo;
            m_NET_AJ_JK_RESULT.RevcInfo = strRevcInfo;
            m_NET_AJ_JK_RESULT.IsSuc = strIsSuc;
            m_NET_AJ_JK_RESULT.LogTime = Convert.ToDateTime(strLogTime);

            if (string.IsNullOrEmpty(strID) == true)
            {
                strID = "-1";
            }

            if (m_NET_AJ_JK_RESULT_BLL.Exists(Convert.ToInt32(strID)) == false)
            {
                m_NET_AJ_JK_RESULT.ID = m_NET_AJ_JK_RESULT_BLL.GetMax_ID();

                if (m_NET_AJ_JK_RESULT_BLL.Insert(m_NET_AJ_JK_RESULT) == true)
                {
                    gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "新增成功！");
                    txtID.Text = Convert.ToString(m_NET_AJ_JK_RESULT.ID);
                }
                else
                {
                    gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "新增失败！");
                }
            }
            else
            {
                if (m_NET_AJ_JK_RESULT_BLL.Update(m_NET_AJ_JK_RESULT, Convert.ToInt32(strID)) == true)
                {
                     gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "更新成功！");
                }
                else
                {
                    gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "更新失败！");
                }
            }
        }
    }
}
